<?php
namespace cms\modules\frontend\controllers;

use Yii;
use common\component\tool\Tool;
use common\component\exception\ErrMap;
use common\component\tool\HttpClient;
use cms\controllers\BasicController;

class SmsController extends BasicController
{

    /*发送验证码 东海期货*/
    public function actionSendMsgDhqh()
    {
        $checkcode = Tool::generateRandomStr(6, 'num');
        if(isset($this->post['phone'])){
            $httpClient = new HttpClient(Yii::$app->params['SMS']['send']);
            $data = [
                'phone' => $this->post['phone'],
                'content' => '验证码为：' . $checkcode . '，您正在注册成为东海期货投资者教育基地用户，感谢您的支持！',
                'type' => 1,
                'code' => $checkcode,
                'appInfoId' => $this->app_info_id
            ];
            $httpClient->data = $data;
            if($res = $httpClient->post() and $res['code'] != 200){
                // P($res);
                return Tool::showRes(ErrMap::getError(10008, $res['msg']));
            }
            return Tool::showRes(ErrMap::getError(0, '发送成功！'));
        }
        return Tool::showRes(ErrMap::getError(10008, '发送失败！'));
    }

    /*验证验证码是否正确*/
    private function checkCode()
    {
        if(isset($this->post['phone']) and isset($this->post['checkcode'])){
            $httpClient = new HttpClient(Yii::$app->params['SMS']['check']);
            $data = [
                'phone' => $this->post['phone'],
                'code' => $this->post['checkcode'],
                'appInfoId' => $this->app_info_id
            ];
            $httpClient->data = $data;
            if($res = $httpClient->post() and $res['code'] != 200){
                // P($res);
                return Tool::showRes(ErrMap::getError(10008));
            }
            return true;
        }
        return Tool::showRes(ErrMap::getError(10008));
    }




}
